package com.xzx.java.kit.basic.trycatch;

import java.util.Scanner;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2018/1/20 17:19
 */
public class StackTraceTest {
    public static int f(int n) {
        System.out.println("f(" + n + ")");
        Throwable throwable = new Throwable();
        StackTraceElement[] stackTraceElements = throwable.getStackTrace();
        for (StackTraceElement element : stackTraceElements) {
            System.out.println(element.toString());
        }
        int r;
        if (n <= 1) {
            r = 1;
        } else {
            r = n * f(n - 1);
        }
        System.out.println("return " + r);
        return r;
    }

    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        System.out.println("Enter n:");
        int n = in.nextInt();
        f(n);
    }
}
